package com.bootcamp.java;

import java.util.Scanner;

/**
 * @program: code
 * @description:
 * @author: Keyu li
 * @create: 2021-08-24 19:57
 **/
public class AfterTaxWages {

    public static double getTax(double salary, int taxRate, int deduct) {
        return salary * taxRate / 100 - deduct;
    }

    public static void main(String[] args) {

        System.out.print("Please input salary (no less than 0): ");
        Scanner sc = new Scanner(System.in);
        double salary, tax;
        salary = Double.parseDouble(sc.nextLine());
        while (salary >= 0) {
            tax = getTaxFromRowSalary(salary);
            System.out.println("the tax you should pay: " + tax);
            System.out.println("salary remains: " + (salary - tax));

            System.out.print("Please input salary (no less than 0): ");
            salary = Double.parseDouble(sc.nextLine());
        }
    }

    private static double getTaxFromRowSalary(double salary) {
        salary -= 2000;
        double tax;
        if (salary <= 0) {
            tax = 0;
        } else if (salary <= 500) {
            tax = getTax(salary, 5, 0);
        } else if (salary <= 2000) {
            tax = getTax(salary, 10, 25);
        } else if (salary <= 5000) {
            tax = getTax(salary, 15, 125);
        } else if (salary <= 20000) {
            tax = getTax(salary, 20, 375);
        } else if (salary <= 40000) {
            tax = getTax(salary, 25, 1375);
        } else if (salary <= 60000) {
            tax = getTax(salary, 30, 3375);
        } else if (salary <= 80000) {
            tax = getTax(salary, 35, 6375);
        } else if (salary <= 100000) {
            tax = getTax(salary, 40, 10375);
        } else {
            tax = getTax(salary, 45, 15375);
        }
        return tax;
    }
}